<template>
  <div>
    <el-row :gutter="15">
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
        <el-col :span="6">
          <el-form-item label="成绩" prop="field101">
            <el-input v-model="formData.grade" placeholder="请输入成绩" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="选课" prop="field103">
            <el-input v-model="formData.course_selection_restrictions" placeholder="请输入选课" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="批次" prop="field105">
            <el-input v-model="formData.fillingBatch" placeholder="请输入批次" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="城市" prop="field104">
            <el-input v-model="formData.city" placeholder="请输入城市" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="专业性质" prop="field109">
            <el-input v-model="formData.nature_of_enrollment" placeholder="请输入专业性质" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item size="large">
            <el-button type="primary" icon="el-icon-search" @click="find" size="mini">查找</el-button>
            <el-button @click="resetForm" size="mini">重置</el-button>
            <el-button @click="submitAll" size="mini"v-hasPermi="['system:collage_department:addList']">全部提交</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="院校" align="center" prop="c_name" />
      <el-table-column label="专业" align="center" prop="d_name" />
      <el-table-column label="城市" align="center" prop="city" />
      <el-table-column label="专业性质" align="center" prop="nature_of_enrollment" />
      <el-table-column label="学制" align="center" prop="educational_system"/>
      <el-table-column label="学费" align="center" prop="tuition"/>
      <el-table-column label="计划数" align="center" prop="twenty_two_year_plan"/>
      <el-table-column label="去年分数" align="center" prop="twenty_one_year_plan"/>
      <el-table-column label="报考建议" align="center" prop="registration_suggestions"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="submit(scope.row)"
            v-hasPermi="['system:collage_department:add']"
          >添加到志愿</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:collage_department:disappear']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="formData.pageNum"
      :limit.sync="formData.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { listPost, getPost, disappear, addPost, addList } from "@/api/system/dept_student";
import {getInfo} from "@/api/login";
export default {
  components: {},
  props: [],
  data() {
    return {
      studentId:{
        id:undefined
      },
      submitDate:[],
      volunteerDate:[],
      loading:true,
      postList:{},
      volunteer:{},
      formData: {
        pageNum: 1,
        pageSize: 10,
        postCode: undefined,
        postName: undefined,
        status: undefined
      },
      rules: {
        field101: [],
        field103: [],
        field105: [],
        field104: [],
        field109: [],
      },
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getList()
  },
  mounted() {},
  methods: {
    handleDelete(get){
      console.log(get.collage_department_id)
      disappear(get.collage_department_id,this.postList).then(response => {
        this.$modal.msgSuccess("删除成功");
        this.postList=response.rows
      });
    },
    submitAll(){
      this.volunteerDate=[]
      let bool=true
      console.log(this.submitDate)
      for (let submit of this.submitDate){
        this.volunteer.sName=submit.c_name
        this.volunteer.dName=submit.d_name
        this.volunteer.educationalSystem=submit.educational_system
        this.volunteer.tuition=submit.tuition
        this.volunteer.natureOfEnrollment=submit.nature_of_enrollment
        this.volunteer.studentId=localStorage.getItem("studentId")
          this.volunteerDate.push(this.volunteer)
        this.volunteer={
          sName:undefined,
          dName:undefined,
          educationalSystem:undefined,
          tuition:undefined,
          natureOfEnrollment:undefined,
          studentId:undefined
        }
      }
      console.log(this.volunteerDate)
      addList(this.volunteerDate).then(response => {
        this.$modal.msgSuccess("新增成功");
      });
    },
    handleSelectionChange(getDate){
      this.submitDate=getDate
    },
    submit(get){
      let submits=confirm("是否确认提交导志愿表")
      if (submits){
        this.volunteer.sName=get.c_name
        this.volunteer.dName=get.d_name
        this.volunteer.educationalSystem=get.educational_system
        this.volunteer.tuition=get.tuition
        this.volunteer.natureOfEnrollment=get.nature_of_enrollment
        this.volunteer.studentId=localStorage.getItem("studentId")
        addPost(this.volunteer).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
        this.volunteer={
          sName:undefined,
          dName:undefined,
          educationalSystem:undefined,
          tuition:undefined,
          natureOfEnrollment:undefined,
          studentId:undefined
        }
      }
    },
    find(){
      this.formData.pageNum = 1;
      this.getList();
    },
    getList(){
      listPost(this.formData).then(response => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    submitForm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        // TODO 提交表单
      })
    },
    resetForm() {
      this.$refs['elForm'].resetFields()
      this.formData={
        grade:undefined,
        course_selection_restrictions:undefined,
        fillingBatch:undefined,
        cith:undefined,
        nature_of_enrollment:undefined
      }
      this.getList()
    },
  }
}

</script>
<style>
</style>
